from google.appengine.ext import db, webapp
from google.appengine.ext.webapp.util import run_wsgi_app

#Applicant Data Model Classes
class ApplicantStub(db.Model):
    password = db.TextProperty() #required=True)
    first_name = db.TextProperty() #required=True)
    middle_initial = db.TextProperty()
    last_name = db.TextProperty() #required=True)
    cell_phone_number = db.PhoneNumberProperty() #required=True)
    email_address = db.EmailProperty()
    security_question_answer = db.TextProperty()
    email_or_text = db.TextProperty() #required=True)
    comments = db.TextProperty(indexed=False)

#Start of HomePage
class HomePage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Home Page 07/07/2012</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab1">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="/">Home</a></li>
	<li class="tab2"><a href="/getstarted">Get Started</a></li>
	<li class="tab3"><a href="/retrieve_results/">Retrieve Results</a></li>
	<li class="tab4"><a href="/admin/">Employers Portal</a></li>
	<li class="tab5"><a href="/admin/">F.A.Q.</a></li>
	<li class="tab6"><a href="/admin/">About ResEdge</a></li>
	</ul>
<h2>Distinguish Yourself And Your Resume with a ResEdge Report!</h2>
<h2>What is a ResEdge Report?</h2>
<p>Prior to actually hiring, most employers do a background screening check. The background check is time consuming and expensive so most employers wait and check only one or two job seekers for each job. The ResEdge report you're about to purchase is a pre-application background screening report that you attache to your resume. In effect, the background check is done for them! The ResEdge report shortcuts the traditional process employers typically have to go thru before hiring a job seeker, and clears the way for you to be hired right away!  You have an edge!  A ResEdge!</p>
<h2>How does the ResEdge process work?</h2>
<p>Fill out the following forms, and pre-authorize payment for the ResEdge Report. We'll run your background screening check and put the resulting ResEdge Report on our password-protected secure servers for you to download and use. Optionally, you may also make your  ResEdge report available directly to potential employers with a special password key you create and provide to them.</p>
<p></p>
<h2>Ready To Learn More?</h2>
<p>Click the <button type=button id="btnGetStarted" style="color:blue" onClick="location.href='/getstarted'"/>Get Started!</button> button.</p>
<p>
<a href="/admin/">Admin Page</a></p>
<hr>
<p>Copyright 2010 by ResEdge LLC, All rights Reserved.  ResEdge is trademarked by ResEdge LLC  Terms and Conditions  Privacy Policy</p>
</body>
</html>
''')
#End of HomePage

#GetStarted page - First Page of Info Gathering
class GetStarted(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
<html>
	<head>		
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Get Started Page 1</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab2">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="/">Home</a></li>
	<li class="tab2"><a href="/getstarted/">Get Started</a></li>
	<li class="tab3"><a href="/retrieve_results/">Retrieve Results</a></li>
	<li class="tab4"><a href="/admin/">Employers Portal</a></li>
	<li class="tab5"><a href="/admin/">F.A.Q.</a></li>
	<li class="tab6"><a href="/admin/">About ResEdge</a></li>
	</ul>
<h2>Distinguish Yourself And Your Resume with a ResEdge Report!</h2>
OK, let's get a Name and Password for you<br>
<form id="frmFirstForm" action="/postappstub" method="post" name="frmElecConsent">
First Name: <input type="text" name="txtFirstName" /> Middle Initial: <input type="text" name="txtMiddleInitial" /> Last Name: <input type="text" name="txtLastName" /><br>
What Password Would You Like To Use: <input type="password" name="txtPassword" /><br><br>
Alright, now a phone number and email address:<br>
Cell Phone #: <input type="tel" name="inPhoneNumber" /> Email Address: <input type="text" name="txtEmailAdd" /><br>
Would you rather have messages from us go to Email or Text Message to Cell Phone? <input type="radio" name="selMessage" value="Email" checked="selected" /> Email<input type="radio" name="selMessage" value="CellPhone" /> Cell Phone<br>
<hr>Please select a Security Question and provide an Answer:<br>
<select name="txtSecQuestion"><option value="1">Mothers' Maiden Name:</option><option value="2">Favorite Color:</option><option value="3">Favorite Season:</option><option value="4">Favorite Month:</option></select> Answer: <input type="text" name="txtSecQuestionAnswer" />
<input type="submit" name="btnSubmitFirstSheet" value="Next" />
</form>
<a href="/show">Show Entities</a></p>
<a href="/admin/">Admin Page</a></p>
<hr>
<p>Click the <button type=button id="btnFinGetStarted" style="color:blue" onClick="location.href='/firstfrm'"/>Finished!</button> button to Submit Your ResEdge Information.</p>
<p>Copyright 2011 by ResEdge LLC, All rights Reserved.  ResEdge is trademarked by ResEdge LLC  Terms and Conditions  Privacy Policy</p> 
</body>
</html>
	''')
#End of GetStarted Page
        
#START: ShowEntitiesPage
class ShowEntities(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/html"
        self.response.out.write("""<html><head><title>ResEdge Show Entities Test Page</title></head>
           <body><p>This is the Show Entities Page!<p><hr><ol>""")
        # Output a list of ApplicantStub entities
        q = ApplicantStub.all()
        for applicants in q:
        	self.response.out.write("<p>Name: %s<br>Email Address: %s</p>" % (applicants.first_name, applicants.email_address))
#        q = db.GqlQuery('SELECT * From ApplicantStub')
        self.response.out.write("""</ol><hr><p><a href="/getstarted">GetStarted Page</a></p></body></html>""")
#END: ShowEntitiesPage 

#Constructor & Posting Of Data
class PostApplicantStub(webapp.RequestHandler):
    def post(self):
    	applicant = ApplicantStub()
        applicant.password = self.request.get("txtPassword")
        applicant.first_name = self.request.get("txtFirstName")
        applicant.middle_initial = self.request.get("txtMiddleInitial")
        applicant.last_name = self.request.get("txtLastName")
        applicant.cell_phone_number = self.request.get("inPhoneNumber")
        applicant.email_address = self.request.get("txtEmailAdd")
        applicant.security_question_answer = (self.request.get("txtSecQuestion")+self.request.get("txtSecQuestionAnswer"))
        applicant.email_or_text = self.request.get("selMessage")
        applicant.comments = self.request.get("txtComments")
        applicant.put()
        self.redirect('/getstarted')
#        self.redirect('/admin/')

application = webapp.WSGIApplication([
    ('/', HomePage),
    ('/getstarted', GetStarted),
    ('/postappstub', PostApplicantStub),
    ('/show', ShowEntities),
], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()